package com.itheima.tlias.mapper;

import com.github.pagehelper.Page;
import com.itheima.tlias.pojo.Emp;
import com.itheima.tlias.pojo.EmpQueryDTO;
import com.itheima.tlias.pojo.ForgetPwdDTO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 06 4月 2025 15:50
 */
@Mapper
public interface EmpMapper {
    /**
     * 查询员工与部门总数
     *
     * @return
     */
//    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id ")
    @Select("select count(*) from emp e ")
    Long count();

    /**
     * 分页查询
     *
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select e.* ,d.name deptName from emp e left join " +
            " dept d on e.dept_id = d.id limit #{start}, #{pageSize} ")
    List<Emp> pageQuery(Integer start, Integer pageSize);

    /**
     * 分页查询
     * 用pageHelper封装的分页参数
     *
     * @param empQueryDTO
     * @return
     */
    Page<Emp> pageQuery1(EmpQueryDTO empQueryDTO);

    /**
     * 添加员工
     *
     * @param emp
     */
/*    @Insert("insert into emp (username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username}, #{password}, #{name}, #{gender}, #{phone}, #{job}, #{salary}, #{image}, #{entryDate}, #{deptId}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")  */
    void addEmp(Emp emp);

    @Select("select * from emp")
    List<Emp> selectList();

    /**
     * 删除员工
     *
     * @param ids
     */
    void deleteById(List<Integer> ids);

    /**
     * 根据id查询员工
     *
     * @param uid
     * @return
     */
    //把查询出来的员工id返回
//    @Options(useGeneratedKeys = true, keyProperty = "id")
//    @Select("select * from emp where id = #{uid}")
//    Emp findById(Integer uid);

    Emp findById(Integer uid);

    /**
     * 更新员工
     *
     * @param emp
     */
    void update(Emp emp);

    @Select("select count(*) from emp where id = #{id}")
    Long existById(Integer id);

    /**
     * 职位数据统计
     *
     * @return
     */
    @MapKey("pos")
    List<Map<String, Object>> getEmpJobData();

    /**
     * 性别数据统计
     *
     * @return
     */
    @MapKey("name")
    List<Map> getEmpGenderData();

    /**
     * 学历数据统计
     *
     * @return
     */
    @MapKey("name")
    List<Map> getStudentDegreeData();

    /**
     * 根据用户名和密码查询员工信息
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);

    /**
     * 查询所有员工的头像
     *
     * @return
     */
    @Select("select image from emp")
    List<String> selectEmpPhotoList();

    /**
     * 根据用户名、姓名、手机号、性别查询用户
     *
     * @param forgetPwdDTO
     * @return
     */
    @Select("select * from emp where username = #{username} and name = #{name} and phone = #{phone} and gender = #{gender}")
    Emp getUserDetial(ForgetPwdDTO forgetPwdDTO);

    /**
     * 修改密码
     *
     * @param emp
     */
    @Update("update emp set password = #{password} where username = #{username}")
    void updateEmpPwd(Emp emp);

    /**
     * 根据用户名查询用户
     *
     * @param userName
     * @return
     */
    @Select("select * from emp where username = #{userName}")
    Emp getUserName(String userName);
}
